package com.tenebrous.jestic.entity;

import lombok.Data;
import org.apache.commons.lang.StringUtils;

import javax.persistence.Id;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
public class TreeSerializable implements Serializable {

    @Id
    private String id;

    private String pid;

    /************************扩展属性***************************/

    @Transient
    private int countChildren;

    @Transient
    private List<TreeSerializable> children = new ArrayList<>();

    public List<TreeSerializable> getChildren2() {
        return this.getChildren() == null || this.getChildren().size() == 0 ? null : this.getChildren();
    }

    public String getPid() {
        if (StringUtils.isBlank(pid)) {
            return "0";
        }
        return pid;
    }

    public Boolean getHasChildren() {
        if (this.getCountChildren() > 0) return true;
        return false;
    }

    public Boolean getLeaf() {
        if (this.getCountChildren() > 0) return false;
        return true;
    }
}